package cn.liulingfengyu.structuralpattern.flyweightpattern;

/**
 * 享元模式示例
 */
public class FlyweightPatternDemo {
    private static final String[] intrinsicStates = {"A", "B", "C", "D", "E"};
    private static final String[] extrinsicStates = {"X", "Y", "Z"};

    public static void main(String[] args) {
        FlyweightFactory factory = new FlyweightFactory();

        for (String intrinsicState : intrinsicStates) {
            Flyweight flyweight = factory.getFlyweight(intrinsicState);
            for (String extrinsicState : extrinsicStates) {
                flyweight.operation(extrinsicState);
            }
        }

        System.out.println("总共享元对象数量：" + factory.getFlyweightCount());
    }
}